#encoding: utf-8
class BlContainersController < ApplicationController
  #集装箱表数据根据报文进行录入，同一箱号的记录会出现多条
  def ctn_history
    begin
      ctn_no = params[:ctn_no].strip if  params[:ctn_no]
      bl_no = params[:bl_no].strip if  params[:bl_no]
      if ctn_no and !ctn_no.strip.empty? and bl_no and !bl_no.strip.empty?
        ctn = BlContainer.where(:ctn_no => ctn_no, :bl_id => Bl.find_all_by_bl_no(bl_no).first.id).first
        ctn_history = ctn.bl_container_histories.order("time ASC")
        if ctn_history.all.size > 0
          gps_history = BlContainerHistory.ctn_history_gps ctn_history
        else
          gps_history = []
        end
        if gps_history.size == 0
          notice = "暂无历史轨迹"
        else
          notice = "查询完成"
        end
        render :json => {:status => 'ok', :notice => notice, :gps_history => gps_history,
                         :ctn_history => render_to_string(:partial => "/utils/ctn_histories.html.erb", :locals => {:ctn_history => ctn_history})}
      else
        render :json => {:status => 'exception', :notice => "页面异常，请刷新页面试试"}
      end
    rescue Exception => e
      logger.error e.message
      render :json => {:status => 'exception', :notice => "系统异常，稍后再试"}
    end
  end

  skip_before_filter :require_login
end
